package route

import (
	_ "pdocker/config"
	"time"

	"github.com/gin-gonic/gin"
	ginSwagger "github.com/swaggo/gin-swagger"

	"github.com/swaggo/gin-swagger/swaggerFiles"
)

// Config will hold services that will eventually be injected into this
// handler layer on handler initialization
type Config struct {
	R               *gin.Engine
	SchedsService   interface{} //service.SchedsService
	TimeoutDuration time.Duration
	MaxBodyBytes    int64
}

// NewHandler initializes the handler with required injected services along with http routes
// Does not return as it deals directly with a reference to the gin Engine
func NewHandler(c *Config) {

	router := c.R

	// Health check
	router.GET("/", Index)

	dockerRouter := router.Group("/docker")
	{
		containerRouter := dockerRouter.Group("/container")
		{
			containerRouter.GET("/list", ShowUserContainers)
			containerRouter.GET("/label", ShowContainerLabel)
		}
		imageRouter := dockerRouter.Group("/image")
		{
			imageRouter.POST("/build", ImageBuild)
			//imageRouter.GET("/build/ws", ImageBuildWS)
			imageRouter.GET("/filter/:name", ImageShow)
			imageRouter.POST("/list", ImageList)
		}
		labRouter := dockerRouter.Group("/lab")
		{
			labRouter.POST("/load", LabLoader)
		}
	}

	taskRouter := router.Group("/task")
	{
		taskRouter.POST("/ctf", CtfTaskCreate)
		taskRouter.DELETE("/ctf", CtfTaskDelete)
		taskRouter.PUT("/ctf", CtfTaskUpdate)

		taskRouter.POST("/lab", LabTaskCreate)
		taskRouter.DELETE("/lab", LabTaskDelete)
		taskRouter.PUT("/lab", LabTaskUpdate)
	}

	schedRouter := router.Group("/time")
	{
		schedRouter.POST("/create", CreateSched)
		schedRouter.PUT("/update", UpdateSched)
	}
	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

}
